package cn.train.controler;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import cn.train.model.Carpiao;
import cn.train.model.Query;
import cn.train.service.QueryTrainService;
import cn.train.util.Pageutil;
@WebServlet("/QueryTrainServlet")
public class QueryTrainServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//分页查询
		String currPage = request.getParameter("pageIndex");
		if (currPage == null) {
			currPage = "1";
		}
		int pageIndex = Integer.parseInt(currPage);
	
		QueryTrainService qts=new QueryTrainService();
		// 总条数
		int count = qts.getCount();
		Pageutil pu = new Pageutil();
		// 总页数
		int totalPage = pu.getTotalPage(count, Pageutil.pageSize);
		if(pageIndex<1){
			pageIndex=1;
		}else if(pageIndex>totalPage){
			pageIndex=totalPage;
		}
		List<Carpiao>list=qts.QueryTain(pageIndex, Pageutil.pageSize);
		//分页查询主代码结束
			request.setAttribute("list", list);
			request.setAttribute("pageIndex", pageIndex);
			request.setAttribute("totalPage", totalPage);
			request.getRequestDispatcher("back/admin/searchTrain.jsp").forward( request,response);
	
		
	
	}
   @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
     doGet(req, resp);
   }
}
